// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import $ from 'jquery'
import echarts from 'echarts'
Vue.prototype.$echarts = echarts
import axios from 'axios'
import VueAxios from 'vue-axios'
import {ApiUrl,returnId} from "../static/js/ApiUrl";

Vue.use(VueAxios,axios);
axios.defaults.withCredentials=true

/*
 * Ajax方法封装{
 * access_token:
 * }
 * */
Vue.prototype.FnAxiosAjax = function (method,url,params,fn){
  let _This = this;
  _This.FangLoading = true;
  let access_token = returnId('access_token');
  if(access_token == '' || access_token == null || access_token == 'undefined'){
    _This.$router.push({path:'login'});
  }
  params.access_token = access_token;
  this.axios({
    method:method,
    url: ApiUrl() + url,
    params:params,
  }).then(function (response) {
    //登陆过期
    if(response.data.retCode == '401'){
      localStorage.removeItem('Fangaccess_token');
      localStorage.removeItem('FangUpadateIndexSorting');
      localStorage.removeItem('userName');
      _This.$router.push({path:'login'});
    }
    // console.log(response.data);
  /*  if(response.data.retCode == '500'){
      _This.$router.push({path:'all404'});
    }*/
    if(response.data && response.data.retCode == '200'){
      !!fn && fn(response.data)
    }else {
      _This.fangerroring = true;
      _This.fangerrorText = response.data.msg;
      _This.setTimeoutError();
    }
    _This.FangLoading = false;
  }).catch(function (error) {
    console.log(error);
    _This.FangLoading = false;
  })
};

// 专业IconFont--JSON封装
Vue.prototype.FnSpecialtyIocnFont = function(index){
  let SpecialtyIcon = {
    '0301':{code: '0301', name: '车站', class: 'icon-zuoce-chezhan', activeclass: 'icon-zuoce-chezhan-gaoliang'},
    '0302':{code: '0302', name: '区间', class: 'icon-zuoce-qujian', activeclass: 'icon-zuoce-qujian-gaoliang'},
    '0303':{code: '0303', name: '轨道', class: 'icon-zuoce-guidao', activeclass: 'icon-zuoce-guidao-gaoliang'},
    '0304':{code: '0304', name: '通信', class: 'icon-zuoce-tongxun', activeclass: 'icon-zuoce-tongxun-gaoliang'},
    '0305':{code: '0305', name: '信号', class: 'icon-zuoce-xinhao', activeclass: 'icon-zuoce-xinhao-gaoliang'},
    '0306':{code: '0306', name: '供电', class: 'icon-zuoce-gongdian', activeclass: 'icon-zuoce-gongdian-gaoliang'},
    '0307':{code: '0307',name: '综合监控（ISCS）',class: 'icon-zuoce-zonghejiankong1',activeclass: 'icon-zuoce-zonghejiankong-gaoliang1'},
    '0308':{code: '0308',ame: '火灾自动报警、环境与设备监控',class: 'icon-zuoce-zonghejiankong',activeclass: 'icon-zuoce-zonghejiankong-gaoliang'},
    '0309':{code: '0309', name: '安防及门禁', class: 'icon-zuoce-anfangmenjin', activeclass: 'icon-zuoce-anfangmenjin-gaoliang'},
    '0310':{code: '0310',name: '通风与空调',class: 'icon-zuoce-tongfengkongtiaoyucainuan',activeclass: 'icon-zuoce-tongfengkongtiaoyucainuan-gaoliang'},
    '0310':{code: '0310',name: '通风与空调',class: 'icon-zuoce-tongfengkongtiaoyucainuan',activeclass: 'icon-zuoce-tongfengkongtiaoyucainuan-gaoliang'},
    '0311':{code: '0311',name: '给排水与消防',class: 'icon-zuoce-geipaishuiyuxiaofang',activeclass: 'icon-zuoce-geipaishuiyuxiaofang-gaoliang'},
    '0312':{code: '0312',name: '自动售检票',class: 'icon-zuoce-zidongshoujianpiao',activeclass: 'icon-zuoce-zidongshoujianpiao-gaoliang'},
    '0313':{code: '0313',name: '车站辅助设备',class: 'icon-zuoce-chezhanfushusheshi',activeclass: 'icon-zuoce-chezhanfushusheshi-gaoliang'},
    '0314':{code: '0314',name: '运营控制中心',class: 'icon-zuoce-yunyingkongzhizhongxin',activeclass: 'icon-zuoce-yunyingkongzhizhongxin-gaoliang'},
    '0315':{code: '0315',name: '车辆基地',class: 'icon-zuoce-cheliangduanyuzonghejidi',activeclass: 'icon-zuoce-cheliangduanyuzonghejidi-gaoliang' },
    '0316':{code: '0316', name: '人防', class: 'icon-zuoce-renfang', activeclass: 'icon-zuoce-renfang-gaoliang'},
    '0317':{code: '0317',name: '建设用地费',class: 'icon-zuoce-jiansheyongdifei',activeclass: 'icon-zuoce-jiansheyongdifei-gaoliang'},
    '0318':{code: '0318', name: '其他费用', class: 'icon-zuoce-qitafeiyong', activeclass: 'icon-zuoce-qitafeiyong-gaoliang'},
    '0319':{code: '0319', name: '预备费用', class: 'icon-zuoce-yubeifeiyong', activeclass: 'icon-zuoce-yubeifeiyong-gaoliang'},
    '0320':{code: '0320',name: '专项费用',class: 'icon-zuoce-zhuanxiangfeiyong',activeclass: 'icon-zuoce-zhuanxiangfeiyong-gaoliang'},
    '0321':{code: '0321', name: '派出所', class: 'icon-zuoce-paichusuo', activeclass: 'icon-zuoce-paichusuo-gaoliang'},
    '0322':{code: '0322',name: '交通衔接',class: 'icon-zuoce-jiaotongxianjiezhuanye',activeclass: 'icon-zuoce-jiaotongxianjiezhuanye-gaoliang'},
  }
  if(SpecialtyIcon[index].class != undefined){
    return SpecialtyIcon[index].class;
  }else {
    return 'icon-zuoce-morenzhuanye'
  }
}
/*过滤器*/
Vue.filter('percentFilters', function (value) {  //精确到小数点两位数，转化为百分比
  if (!value) return 0;
  return (value*100).toFixed(2) + '%'
});
Vue.filter('ceilFilters', function (value) {  //向上取整
  if (!value) return '';
  return Math.ceil(value)
});
Vue.filter('roundFilters', function (value) {  //保留小数点两位数
  if (!value) return 0;
  return Math.round(value*100)/100
});
Vue.filter('quarterFilters', function (value) {  //月份转化为季度   201701
  if (!value) return '';
  // let timeData = '';
  let years = value.toString().substring(0,4)+'年';  //切割年份
  let moons = value.toString().substring(value.toString().length-2);  //切割月份
  let parseNum = parseFloat(moons);  //转化为数字类型
  if(parseNum<4){
    value = years + '第一季度'
  }else if(3<parseNum && parseNum<7){
    value = years + '第二季度'
  }else if(6<parseNum && parseNum<10){
    value = years + '第三季度'
  }else if(9<parseNum && parseNum<13){
    value = years + '第四季度'
  }
  return value
});

new Vue({
  el: '#app',
  router,
  /*components: { App },
  template: '<App/>'*/
  render: h => h(App)
})

